/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.fzhucc.modules.sciStudio.repository;

import com.fzhucc.modules.sciStudio.domain.SciStudio;
import com.fzhucc.modules.sciStudio.domain.SciStudioInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * @author yyg
 * @website https://eladmin.vip
 * @date 2024-01-10
 **/
public interface SciStudioRepository extends JpaRepository<SciStudio, Integer>, JpaSpecificationExecutor<SciStudio> {

    @Query(nativeQuery = true, value = "select * from tb_sci_studio where model_id=:mdId and is_delete=0 and audit_status=:shstatus")
    List<SciStudio> findByMdId(int mdId, String shstatus);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_studio where is_delete=0  and org_area like:area and audit_status=:auditStatus")
    int findCountNormalByLikeArea(String area, String auditStatus);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_studio where is_delete=0  and org_area like:area and audit_status=:auditStatus and create_time<=:eTime")
    int findCountNormalByLikeAreaWithTime(String area, String auditStatus, Date eTime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_studio where is_delete=0 and org_area like :area and audit_status=:auditStatus and create_time<=:btime and create_time>=:atime")
    int findNormalByLikeAreaWithOutIsShowCSevenCreate(String area, String auditStatus, Date atime, Date btime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_studio where is_delete=0 and org_area like :area and audit_status=:auditStatus and delete_time<=:btime and delete_time>=:atime")
    int findNormalByLikeAreaWithOutIsShowDSevenDel(String area, String auditStatus, Date atime, Date btime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_studio where is_delete=0 and org_area like :area and audit_status like:auditStatus and create_time<=:btime and create_time>=:atime")
    int findNormalByLikeAreaWithOutIsShowCSevenCreateLikeDsh(String area, String auditStatus, Date atime, Date btime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_studio where is_delete=0 and org_area like :area and audit_status like:auditStatus and create_time<=:btime ")
    int findNormalByLikeAreaWithOutIsShowCSevenCreateLikeDshWithOutS(String area, String auditStatus,  Date btime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_studio where is_delete=0 and org_area like :area and audit_status not like:auditStatus and create_time<=:btime ")
    int findNormalByLikeAreaWithOutIsShowCSevenCreateLikeDshWithOutSNotLike(String area, String auditStatus,  Date btime);
}